<?php
if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
	exit('Access Denied');
}
if (!function_exists('fsockopen') && !function_exists('pfsockopen')) {
	cpmsg_error(lang('plugin/xunku_spider_2012', 'network_can_use'));
}
define('CHARSET',$_G['charset']);
define('SPIDER','xunku');
define('D_P',DISCUZ_ROOT);
define('H_P',DISCUZ_ROOT.'source/plugin/xunku_spider_2012/');
define('SPIDER_LIBRARY_DIR',H_P.'library/');
define('SPIDER_REQUIRE_DIR',H_P.'require/');
$basename = 'admin.php?action=plugins&operation=config&do='.$pluginid.'&identifier='.$_G['gp_identifier'];
error_reporting(0);
//error_reporting(E_ALL);
require_once(SPIDER_REQUIRE_DIR.'xk_config.php');
require_once(SPIDER_REQUIRE_DIR.'xk_common.php');
require_once(SPIDER_LIBRARY_DIR.'api/ApiClient.php');
$api_client = new ApiClient();
check_ownkey();
check_sql();
if(!is_file(D_P.'data/plugindata/xk_baseconfig.php')){
	default_baseconfig_set();
}
$step = getgpc('step');
if (!$step) {
	$result = $api_client->execute('get_source_rules',array(
															'xk_publickey'=>$xk_publickey,
															'source_type' => 1,
														));
		$rules = $result['data'];
} else {
	$source_title = getgpc('source_title');
	$source_url = getgpc('source_url');
	$source_desc = getgpc('source_desc');
	$result = $api_client->execute('submit_source_rule',array(
													'xk_publickey'=>$xk_publickey,
													'source_title' => $source_title,
													'source_url' => $source_url,
													'source_desc' => $source_desc,
													'source_type' => 1
												));
	if ($result['statue']) {
		cpmsg(lang('plugin/xunku_spider_2012', 'action_success'), dreferer(), 'succeed');
	} else {
		cpmsg_error(lang('plugin/xunku_spider_2012', 'action_error'));
	}
}
if(CHARSET == 'gbk') {
	include template('xunku_editor_spider:help');	
} else {
	include template('xunku_editor_spider:help_utf');	
}
?>